WA Templated Message
Sending a message outside of a 24-hour customer care session requires an approved template All marketing, utility or authentication conversations on the WhatsApp channel must start with an “Opt-In” by the user. This can be collected through any third party channel. For example in an SMS message, a web form, or email.
When sending a template message, you need to specify the template name, language code, and the set of parameters defined in the template. Conversation API provides the capability to send channel-specific templates that use a key-value dictionary to specify the template parameters. Each key in the dictionary corresponds to a property of a template parameter as they're defined in WhatsApp public documentation for media and interactive templates.
The format of the keys in the parameter dictionary is of the following form:
<component_type>[<component_index>]<component_sub_type>[<parameter_index>]<parameter_field>
where: • component_type must be set to one of header , body or button . • component_index is a 0-based index of the button in the template. There can be, at most, three buttons. The component_index key is present and required only for button components. • component_sub_type is present and required only for button components. It's set to either quick_reply or url . • parameter_index is a 1-based index of the parameter for the given component. • parameter_field is a property of the parameter. It can be one of text , payload , document. , image. , or video.*
While sending the Templated message on WhatsApp- enterprise have to provide channel_template object which consist of following attributes.
Attribute | Description |
---|---|
template_id required | String The ID of the template. |
version required | String Used to specify what version of a template to use. This will be used in conjunction with language_code. |
language_code | String |
parameters | object Required if the template has parameters. Concrete values must be present for all defined parameters in the template. Parameters can be different for different versions and/or languages of the template. |
Sample Payload Structure-
Case-1- Text Message
{
"message": {
"template_message": {
"channel_template": {
"WHATSAPP": {
"template_id": "text_template",
"language_code": "en",
"parameters": {
"body[1]text": "Value of first parameter",
"body[2]text": "Value of second parameter",
"body[3]text": "Value of third parameter"
}
}
}
}
}
}
Case-2 Media Template Message with Image
The parameter fields for sending an image are:
Parameter field key | Description | Required |
---|---|---|
header[1]image.link | The URL of the image. | Yes |
header[1]image.provider.name | Provider to use when downloading the file | No |
{
"message": {
"template_message": {
"channel_template": {
"WHATSAPP": {
"template_id": "text_template",
"language_code": "en",
"parameters": {
"header[1]image.link":"https://example.com/image.jpg",
"body[1]text": "Value of first parameter"
}
}
}
}
}
}
Case-3 Media Template Message with Video
The parameter fields for sending an image are:
Parameter field key | Description | Required |
---|---|---|
header[1]video.link | The URL of the video. | Yes |
header[1]video.provider.name | Provider to use when downloading the file | No |
{
"message": {
"template_message": {
"channel_template": {
"WHATSAPP": {
"template_id": "text_template",
"language_code": "en",
"parameters": {
"header[1]video.link":"https://example.com/video.mp4",
"body[1]text": "Value of first parameter"
}
}
}
}
}
}
Case-4 Media Template Message with Video
The parameter fields for sending an image are:
Parameter field key | Description | Required |
---|---|---|
header[1]document.link | The URL of the document. | Yes |
header[1]document.provider.name | Provider to use when downloading the file | No |
header[1]document.filename | Filename of the document. | No |
{
"message": {
"template_message": {
"channel_template": {
"WHATSAPP": {
"template_id": "text_template",
"language_code": "en",
"parameters": {
"header[1]document.link":"https://example.com/document.pdf",
"header[1]document.filename":"document.pdf",
"body[1]text": "Value of first parameter"
}
}
}
}
}
}
Case-5 Location Message
The parameter fields for sending an image are:
Parameter field key | Description | Required |
---|---|---|
header[1]location.longitude | Longitude of the Location | Yes |
header[1]location.latitude | Latitude of the Location | Yes |
header[1]location.name | Name of the Location | No |
header[1]location.address | Address of the Location | No |
{
"message": {
"template_message": {
"channel_template": {
"WHATSAPP": {
"template_id": "text_template",
"language_code": "en",
"parameters": {
"header[1]location.latitude":59.33273686980,
"header[1]location.longitude":18.33273686980,
"header[1]location.name":"Sinch office",
"header[1]location.address":" Sinch office",
"body[1]text": "Value of first parameter"
}
}
}
}
}
}
Case-7 Interactive Message
Interactive templates allow you to send messages that include interactive buttons. WhatsApp offers two types of predefined buttons:
• Quick Reply - Presents a button with predefined text which, when clicked, then returns a callback with a defined payload.
• Call-to-Action - Presents a clickable action in WhatsApp to either call a phone number or to visit a website.
These buttons can be attached to both text and media templates.
The parameter fields for sending an image are:
Parameter field key | Description | Required |
---|---|---|
button[n]url[1]text | Dynamic URL suffix for the URL button | Yes, if button at index n is a URL button |
button[m]quick_reply[1]payload | Postback payload to be returned | Yes, if button at index m is a quick_reply button |
where n and m are indices of the buttons in the template.
When adding a quick_reply button, the payload field must be set even when empty. For example, you can set the quick_reply button at index 0 to be empty by adding the following entry in the parameter dictionary:
"button[0]quick_reply[1]payload": "
Quick Reply Button message
{
"message": {
"template_message": {
"channel_template": {
"WHATSAPP": {
"template_id": "text_template",
"language_code": "en",
"parameters": {
"header[1]text":" Value of header parameter ",
"body[1]text": "Value of first parameter",
"button[0]quick_reply[1]payload": "button0clicked",
"button[1]quick_reply[1]payload": "button1clicked",
"button[2]quick_reply[1]payload": "button2clicked"
}
}
}
}
}
}
Call-to-Action message
{
"message": {
"template_message": {
"channel_template": {
"WHATSAPP": {
"template_id": "text_template",
"language_code": "en",
"parameters": {
"header[1]text":" Value of header parameter ",
"body[1]text": "Value of first parameter",
"button[0]url[1]text": " Value for URL suffix button 1",
"button[1]url[1]text": " Value for URL suffix button 2",
}
}
}
}
}
}